/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘国水
 * Date: 2025-05-01
 * Time: 23:44
 */
public class test {
    static class treeNode {
        public char val;
        public treeNode left;
        public treeNode right;

        public treeNode(char val) {
            this.val = val;
        }
    }

    public treeNode root;//当前二叉树的根节点

    public treeNode createTree() {
        treeNode A = new treeNode('A');
        treeNode B = new treeNode('B');
        treeNode C = new treeNode('C');
        treeNode D = new treeNode('D');
        treeNode E = new treeNode('E');
        treeNode F = new treeNode('F');
        treeNode G = new treeNode('G');
        treeNode H = new treeNode('H');


        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        E.right = H;
        C.left = F;
        C.right = G;
        return A;
    }

    // 前序遍历
    public void preOrder(treeNode root) {
        if(root == null) {
            return;
        }
        System.out.print(root.val +" ");
        preOrder(root.left);
        preOrder(root.right);

    }

    // 中序遍历
    public void inOrder(treeNode root) {
        if(root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val +" ");
        inOrder(root.right);
    }

    // 后序遍历
    public void postOrder(treeNode root) {
        if(root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val +" ");
    }

    public static int count = 0;

    // 获取树中节点的个数 遍历思路
    public void size(treeNode root) {
        if (root == null) {
            return;
        }
        count++;
        size(root.left);
        size(root.right);
    }

    //子问题思路
    public int NodeSize(treeNode root) {
        if(root == null) {
            return 0;
        }
        return NodeSize(root.left) + NodeSize(root.right) + 1;
    }

    // 获取叶⼦节点的个数
    int getLeafNodeCount(treeNode root) {
        return 0;
    }
    // ⼦问题思路-求叶⼦结点个数

    // 获取第K层节点的个数
    int getKLevelNodeCount(treeNode root, int k) {
        return 0;
    }

    // 获取⼆叉树的⾼度
    int getHeight(treeNode root) {
        return 0;
    }

    // 检测值为value的元素是否存在
//    TreeNode find(TreeNode root, int val) {
//        if(root == null) {
//            return null;
//        }
//
//    }

    //层序遍历
    void levelOrder(treeNode root) {

    }

    // 判断⼀棵树是不是完全⼆叉树
    boolean isCompleteTree(treeNode root) {
        return true;
    }

    public treeNode invertTree(treeNode root) {
        if (root == null) {
            return null;
        }
        treeNode temp;
        while (root != null) {
            temp = root.left;
            root.left = root.right;
            root.right = temp;
            root = root.left;
        }
        return root;
    }
}
